﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;

/// <summary>
/// DataComponet 的摘要说明
/// </summary>
public class DataComponent
{
	public DataComponent()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
        
        
	}

    public DataSet GetScoreByName(string UserName)
    {
        DataSet ds = new DataSet();
        DataTable ScoreTable = new DataTable("Score");

        ds.Tables.Add(ScoreTable);
        DataColumn Id = new DataColumn("Id", typeof(string));
        DataColumn Name = new DataColumn("Name", typeof(string));
        DataColumn Score = new DataColumn("分数", typeof(string));

        ds.Tables["Score"].Columns.Add(Id);
        ds.Tables["Score"].Columns.Add(Name);
        ds.Tables["Score"].Columns.Add(Score);

        //for (int i = 0; i < 50; ++i)
        //{
            object[] newRow = new object[3];
            // Set the values of the array.
            newRow[0] = "1";
            newRow[1] = UserName;
            newRow[2] = "98";


            ds.Tables["Score"].BeginLoadData();
            // Add the new row to the rows collection.
            ds.Tables["Score"].LoadDataRow(newRow, true);
            ds.Tables["Score"].EndLoadData();


        //}
        return ds;
    }

    public void UpdateStaffById()
    {

    }
    

    public int GetItemCount()
    {
        //Test
        return 50;
    }

    
    public DataSet GetStaffScoreList(int startRowIndex, int maximumRows)
    {
        DataSet ds = new DataSet();
        DataTable ScoreTable = new DataTable("Score");

        ds.Tables.Add(ScoreTable);
        DataColumn Id = new DataColumn("编号", typeof(string));
        DataColumn Name = new DataColumn("姓名", typeof(string));
        DataColumn Score = new DataColumn("分数", typeof(string));

        ds.Tables["Score"].Columns.Add(Id);
        ds.Tables["Score"].Columns.Add(Name);
        ds.Tables["Score"].Columns.Add(Score);

        for (int i = 0 + startRowIndex; i < startRowIndex + maximumRows; ++i)
       {
        object[] newRow = new object[3];
        // Set the values of the array.
        newRow[0] = "1";
        newRow[1] = "部门评分";
        newRow[2] = Convert.ToString(i + 50);


        ds.Tables["Score"].BeginLoadData();
        // Add the new row to the rows collection.
        ds.Tables["Score"].LoadDataRow(newRow, true);
        ds.Tables["Score"].EndLoadData();


       }
        return ds;
    }

 

  

    public DataSet InsertDepartment(StaffDetail item)
    {
        
        return new DataSet();
    }
    
    public static MySqlCommand CreateMySqlProcCmd(string proc, MySqlConnection conn)
    {
        MySqlCommand cmd = new MySqlCommand(proc, conn);
        cmd.CommandType = CommandType.StoredProcedure;
        return cmd;
    }

    public static void AddCmdParameters(MySqlCommand cmd, string procPara, MySqlDbType type, int size, object value)
    {
        cmd.Parameters.Add(new MySqlParameter(procPara, type, size));
        cmd.Parameters[procPara].Value = value;
    }


    public static void AddCmdOutParameters(MySqlCommand cmd, string procPara, MySqlDbType type, int size)
    {
        cmd.Parameters.Add(new MySqlParameter(procPara, type, 10));
        cmd.Parameters[procPara].Direction = ParameterDirection.Output;
    }

    public static void ExecNonQueryCmd(MySqlCommand cmd, MySqlConnection conn)
    {
        try
        {
            conn.Open();
            cmd.ExecuteNonQuery();
        }
        catch (MySqlException err)
        {
            throw new ApplicationException(err.ToString());
        }
        finally
        {
            conn.Close();
        }
    }

};
